home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / HelpGetProc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  5.8 KB  |  169 lines  |  [TEXT/KAHL]

  1.  /************************************************************************************/
  2. /*    HelpGetProc            C14Calculator                                                */
  3. /************************************************************************************/
  4. /*    How to set up this Help facility:                                                */
  5. /*                                                                                    */
  6. /*    Help 'TEXT' resources run in sequence, beginning with number 1000.  The count    */
  7. /*    is the symbol "helpCount" which is in the header file.  The first 31 characters,*/
  8. /*    followed by a carriage return, are used to build the index.  A "blank" entry    */
  9. /*    is 33 characters long:  31 blanks, a carriage return, and one more blank for    */
  10. /*    the text.  The character set is monaco 9.  With this font, the text area is 21    */
  11. /*    lines of 40 characters.  It's easiest to create the text with an editor which    */
  12. /*    will display monaco 9, then cut and paste into ResEdit.                            */
  13. /************************************************************************************/
  14.  
  15.  
  16. #include     "HelpGetProc.h"
  17. #ifndef __C14__
  18. #include    "C14 Calculator.h"
  19. #endif
  20. #include    "TE32K.h"
  21. #include     "myClickLoop.h"
  22. #include     "myActionProc.h"
  23. #include     "Globals.h"
  24. #include    "helpCount.h"
  25. #include    <stdlib.h>
  26.  
  27. void    HelpGetSeg()    {}        /*  for reference in "UnloadSeg()" calls    */
  28.  
  29. short HelpGetProc ()
  30. {
  31.     Handle        helpHandle;
  32.     short        HGRetCode = 0;
  33.     div_t        r;                                    /* work area for division        */
  34.     Rect        dataBounds = {0,0, 1,1};
  35.     Point        cSize = {12,200};
  36.     short        h,v;
  37.     short        j;
  38.     long        helpLong;
  39.     ControlActionUPP    myNewActionProc;
  40.     
  41.     myNewActionProc = NewControlActionProc((ProcPtr)myActionProc);
  42.     
  43.     if (windTbl[1].windPtr != 0)                    /* if help is already present    */
  44.         {
  45.         SelectWindow(windTbl[1].windPtr);            /* just activate the window        */
  46.         goto ENDING;
  47.         }
  48.  
  49.  
  50.     windTbl[1].windPtr =                                /* point to data area        */
  51.             (WindowPtr) &windTbl[1].windRec;
  52.     if (useColor[0])
  53.         windTbl[1].windPtr =                                 /* get color template*/
  54.                 GetNewCWindow (130, windTbl[1].windPtr, (WindowPtr) -1);
  55.     else
  56.         windTbl[1].windPtr =                                 /* get the template        */
  57.                 GetNewWindow (130, windTbl[1].windPtr, (WindowPtr) -1);
  58.     
  59.     windTbl[1].windRec.refCon = ProcHelp;                /* save window type            */
  60.     windTbl[1].windPathRefNum = 0;                        /* clear path ref number    */
  61.     windTbl[1].windTEChanged = FALSE;                    /* no data changed yet        */
  62.  
  63.     v = qd.screenBits.bounds.bottom - 5                    /* compute location            */
  64.         -(windTbl[1].windRec.port.portRect.bottom        /* centered at the bottom    */
  65.             - windTbl[1].windRec.port.portRect.top);
  66.     h = (qd.screenBits.bounds.right
  67.         -(windTbl[1].windRec.port.portRect.right
  68.             - windTbl[1].windRec.port.portRect.left)) * 0.5;
  69.     MoveWindow (windTbl[1].windPtr, h, v, TRUE);    /* position window on desktop    */
  70.  
  71.     SetPort (&windTbl[1].windRec.port);                    /* set this as the grafPort    */
  72.     TextFont(monaco);                                    /* choose the font...        */
  73.     TextFace(NIL);                                        /* ... style, and..            */
  74.     TextSize(9);                                        /* ... size                    */
  75.  
  76.     workRect = windTbl[1].windRec.port.portRect;
  77.     viewRect = workRect;
  78.     viewRect.right -= 18;
  79.     viewRect.left = viewRect.right - 255;
  80.     viewRect.top = viewRect.bottom - 233;
  81.     viewRect.bottom -= 2;
  82.     destRect = viewRect;
  83.     destRect.right -= 6;
  84.     destRect.left += 6;
  85.     windTbl[1].windTEH[0] =
  86.             TENew (&destRect, &viewRect);                /* create TE Record            */
  87.     
  88.     /********************* install click loop ****************/
  89.     //SetClikLoop ((UniversalProcPtr) myClikLoop,windTbl[1].windTEH[0]);
  90.     /****************** end of install click loop ************/
  91.     /* install click loop        */
  92.     
  93.     TEAutoView (TRUE, windTbl[1].windTEH[0]);            /* enable AutoScroll        */
  94.     TESetSelect (0,0, windTbl[1].windTEH[0]);            /* caret to top                */
  95.     
  96.     windTbl[1].windTEHCount = 1;                        /* one TE field is defined    */
  97.     windTbl[1].windTEHSub = 0;                            /* go to first TE area        */
  98.  
  99.  
  100.  
  101.     workRect = (**windTbl[1].windTEH[0]).viewRect;
  102.     windTbl[1].windCntlH[0] =                             /* get the control        */
  103.             GetNewControl (128, windTbl[1].windPtr);
  104. //    #ifdef    powerc
  105.         SetCtlAction (windTbl[1].windCntlH[0],                /* install own action    */
  106.                 (ControlActionUPP) myNewActionProc);
  107. //    #else
  108. //        SetCtlAction (windTbl[1].windCntlH[0], myActionProc);
  109. //    #endif
  110.     SizeControl (windTbl[1].windCntlH[0], 16,            /* size to fit window    */
  111.             workRect.bottom - workRect.top + 2);
  112.     MoveControl (windTbl[1].windCntlH[0],                /* move onto window        */
  113.             workRect.right, workRect.top - 1);
  114.     ShowControl (windTbl[1].windCntlH[0]);                /* make it visible        */
  115.     
  116.     windTbl[1].windCntlHCount = 1;                        /* one Control is defined    */
  117.     windTbl[1].windCntlHSub = 0;                        /* go to first Control        */
  118.     
  119.     workRect = windTbl[1].windRec.port.portRect;
  120.     workRect.left += 4;
  121.     workRect.right = workRect.left + 200;
  122.     workRect.bottom -=2;
  123.     workRect.top = workRect.bottom - 204;
  124.  
  125.     helpList = LNew(&workRect, &dataBounds, cSize,            /* create the list        */
  126.             NIL, windTbl[1].windPtr, TRUE, FALSE, FALSE, TRUE);
  127.     (**helpList).selFlags = lOnlyOne + lNoNilHilite;    /* set flags for cursor        */
  128.  
  129.     ShowWindow (windTbl[1].windPtr);
  130.  
  131.     helpCell.h = 0;
  132.     helpCell.v = 0;
  133.     j=0;
  134.     LAddRow (helpCount-1, 1, helpList);
  135.     helpHandle = (Handle) -1;                /* assign non-null for loop                */
  136.     for (j=0; j<helpCount; j++)                /* helpCount defined in HelpGetProc.h    */
  137.         {
  138.         helpHandle = GetResource ('TEXT', 1000+j);
  139.         HLock (helpHandle);
  140.         if (helpHandle)
  141.             {
  142.             if ( (SizeResource(helpHandle)) > 32)
  143.                 LSetCell (*helpHandle, 31, helpCell, helpList);
  144.             else
  145.                 LClrCell (helpCell, helpList);
  146.             helpCell.v++;
  147.             }
  148.         HUnlock (helpHandle);
  149.         ReleaseResource (helpHandle);
  150.         }
  151.  
  152.     helpHandle = GetResource('TEXT', 1000);        /* get "How to Use Help" TEXT        */
  153.     HLock (helpHandle);
  154.     helpLong = SizeResource(helpHandle);        /* get TEXT size                    */
  155.     TESetText (*helpHandle+32, helpLong-32, windTbl[1].windTEH[0]);
  156.     TECalText (windTbl[1].windTEH[0]);
  157.     helpCell.v = 0;
  158.     helpPrev = 0;
  159.     LSetSelect (TRUE, helpCell, helpList);
  160.     HUnlock (helpHandle);
  161.     ReleaseResource (helpHandle);
  162.  
  163.     InvalRect (&windTbl[1].windRec.port.portRect);        /* request redraw        */
  164.  
  165.  
  166. ENDING:        
  167.     return HGRetCode;
  168. }
  169.